package com.yunquan.ohana.ui.web

import android.os.Bundle
import android.view.View
import android.webkit.WebSettings
import android.webkit.WebViewClient
import com.yunquan.ohana.BR
import com.yunquan.ohana.R
import com.yunquan.ohana.base.ui.BaseActivity
import com.yunquan.ohana.databinding.ActivityWebBinding

class WebActivity : BaseActivity<ActivityWebBinding, WebViewModel>() {

    private var mUrl: String? = null

    override fun initContentView(savedInstanceState: Bundle?): Int {
        return R.layout.activity_web
    }

    override fun initVariableId(): Int {
        return BR.webViewModel
    }

    override fun initParam() {
        super.initParam()
        window.statusBarColor = resources.getColor(R.color.background)
        window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
    }

    override fun initData(savedInstanceState: Bundle?) {
        super.initData(savedInstanceState)
        val bundle = intent.extras
        bundle?.let {
            mUrl = it.getString("url")
            viewModel!!.title.set(it.getString("title"))
        }
        binding!!.webview.settings.javaScriptEnabled = true
        binding!!.webview.settings.setRenderPriority(WebSettings.RenderPriority.HIGH)
        binding!!.webview.settings.loadsImagesAutomatically = true
        binding!!.webview.webViewClient = WebViewClient()
        if (mUrl != null) {
            binding!!.webview.loadUrl(mUrl!!)
        }
    }
}